package com.wb.mianxiangduixiang.bms;

/**
 * @author 黄衡熙
 * @version 1.0
 * @date 2025年07月22日14:20
 */
//信用账户
public class CreditAccount extends Account {

    // 信用额度
    private double limit;

    public double getLimit() {
        return limit;
    }

    public void setLimit(double limit) {
        this.limit = limit;
    }

    @Override
    //信用账户取款
    public boolean withdrawMoney(double money) {
        if(money <=(getLimit()+super.getBalance())) {
            if(super.getBalance()>=money) {
                super.setBalance(super.getBalance()-money);
                System.out.println("恭喜您，取款成功，当前您的信用账户余额为："+super.getBalance()+" 可用信用额度还剩:"+this.getLimit());
            }else{
                setLimit(getLimit()+super.getBalance()-money);
                super.setBalance(0.0);
                System.out.println("恭喜您，取款成功，当前您的信用账户余额为："+super.getBalance()+" 可用信用额度还剩:"+this.getLimit());
            }
        }else{
            System.out.println("取款失败，当前账户余额加透支余额不足以支持您的取款");
        }
        // 信用账户存在信用额度,因此取款的时候需要考虑账户余额与信用额度
        return false;
    }
    //信用账户转账
    public boolean transferMoney(double money, Account account1) {
        if(money <=(getLimit()+super.getBalance())) {
            if(super.getBalance()>=money) {
                super.setBalance(super.getBalance()-money);
                System.out.println("恭喜您，转账成功，当前您的信用账户余额为："+super.getBalance()+" 可用信用额度还剩:"+this.getLimit());
                account1.setBalance(account1.getBalance()+money);
            }else{
                setLimit(getLimit()+super.getBalance()-money);
                super.setBalance(0.0);
                System.out.println("恭喜您，转账成功，当前您的信用账户余额为："+super.getBalance()+" 可用信用额度还剩:"+this.getLimit());
                account1.setBalance(account1.getBalance()+money);
            }
        }else{
            System.out.println("转账失败，当前账户余额加透支余额不足以支持您的取款");
        }
        // 信用账户存在信用额度,因此转账的时候需要考虑账户余额与信用额度
        return false;
    }
}